package com.sen.controller;

import com.sen.dto.Video;
import com.sen.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/video")// 模块根路径
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 根据bv号查视频
     * @param bv
     * @return
     */
    @RequestMapping("/{bv}")//浏览器地址
    @ResponseBody // 返回对象要的注解
    public Video video(@PathVariable String bv){
        return  videoService.find(bv);
    }

    /**
     * 发布视频接口
     * @param video
     * @return
     */
    @RequestMapping("/publish")
    @ResponseBody
    public Map<String,String> publish(@RequestBody Video video){
        String bv = videoService.publish(video);
        return Map.of("bv",bv);
    }

}
